/*
 * 版权：河南白菜淘信息技术有限公司 版权所有
 * @author Zhaimm
 * 创建日期：2020/8/31 2:29 PM
 * 文件名：public_utils
 */

import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';


class KeepAliveWidget extends StatefulWidget {
  final Widget child;

  const KeepAliveWidget(this.child);

  @override
  State<StatefulWidget> createState() => KeepAliveState();
}

class KeepAliveState extends State<KeepAliveWidget> with AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return widget.child;
  }
}

/// 适配字体
double setSp(double sp) {
  return ScreenUtil.getInstance().setSp(sp);
}

/// 适配宽度
double setWidth(double width) {
  return ScreenUtil.getInstance().setWidth(width);
}

/// 适配高度
double setHeight(double height) {
  return ScreenUtil.getInstance().setHeight(height);
}

/// 提示
void toast(String msg, {Toast toastLength}) {
  Fluttertoast.showToast(
    msg: msg,
    toastLength: toastLength ?? Toast.LENGTH_SHORT,
    gravity: ToastGravity.CENTER,
    timeInSecForIos: 1,
    backgroundColor: Colors.black,
    textColor: Colors.white,
    fontSize: 16.0,
  );
}

bool isNotEmptyString(String str) {
  if (str != "" && str != "null" && str != "NULL" && str != null) {
    return true;
  }
  return false;
}